import re
import json

data = [[], [], [], []]

with open('./data/无人机每一帧真实位置.txt', 'r', encoding='utf8') as f:
    line = f.readline()
    i = 0
    write_line = ""
    while line:
        a = re.search(r"X=.* Y", line)
        X = a.group()[2:-3]
        b = re.search(r"Y=.* Z", line)
        Y = b.group()[2:-3]
        c = re.search(r"Z=.*", line)
        Z = c.group()[2:10]

        frame = c.group()[10:]

        if i % 3 == 0:
            write_line = ""
            str_tmp = ",".join([frame, X, Y, Z])
            write_line += str_tmp
            write_line += ","
        if i % 3 == 1:
            str_tmp = ",".join([X, Y, Z])
            write_line += str_tmp
            write_line += ","
        if i % 3 == 2:
            str_tmp = ",".join([X, Y, Z])
            write_line += str_tmp
            print(write_line)

        i += 1
        line = f.readline()
